<template>
  <div class="service-cards">
    <!-- 搜索区域 -->
    <div class="search-section">
      <div class="container search-container">
        <el-tabs v-model="activeTab">
          <el-tab-pane label="采购公告检索" name="announcement"></el-tab-pane>
          <el-tab-pane label="采购意向检索" name="intention"></el-tab-pane>
          <el-tab-pane label="供应商信息检索" name="supplier"></el-tab-pane>
        </el-tabs>

        <el-form :model="searchForm" label-width="80px">
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="公告标题">
                <el-input v-model="searchForm.title" placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="采购人">
                <el-input v-model="searchForm.purchaser" placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="项目编号">
                <el-input v-model="searchForm.projectNumber" placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="代理机构">
                <el-input v-model="searchForm.publishOrgin" placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-form-item label="发布时间">
            <el-radio-group v-model="searchForm.timeRange">
              <el-radio label="all">不限</el-radio>
              <el-radio label="today">今天</el-radio>
              <el-radio label="3days">近3天</el-radio>
              <el-radio label="7days">近7天</el-radio>
              <el-radio label="1month">近1个月</el-radio>
              <el-radio label="3months">近3个月</el-radio>
              <el-radio label="6months">近6个月</el-radio>
              <el-radio label="1year">近1年</el-radio>
              <el-radio label="3years">近3年</el-radio>
              <el-radio label="5years">近5年</el-radio>
            </el-radio-group>
            <el-date-picker
              v-if="searchForm.timeRange === 'custom'"
              v-model="searchForm.customDateRange"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>

          <el-form-item label="归属区域">
            <el-radio-group v-model="searchForm.region">
              <el-radio label="all">不限</el-radio>
              <el-radio label="zhengzhou">郑州市</el-radio>
              <el-radio label="kaifeng">开封市</el-radio>
              <el-radio label="luoyang">洛阳市</el-radio>
              <el-radio label="pingdingshan">平顶山市</el-radio>
              <el-radio label="anyang">安阳市</el-radio>
              <el-radio label="hebi">鹤壁市</el-radio>
              <el-radio label="xinxiang">新乡市</el-radio>
              <el-radio label="jiaozuo">焦作市</el-radio>
              <el-radio label="puyang">濮阳市</el-radio>
              <el-radio label="xuchang">许昌市</el-radio>
              <el-radio label="luohe">漯河市</el-radio>
              <el-radio label="sanmenxia">三门峡市</el-radio>
              <el-radio label="nanyang">南阳市</el-radio>
              <el-radio label="shangqiu">商丘市</el-radio>
              <el-radio label="xinyang">信阳市</el-radio>
              <el-radio label="zhoukou">周口市</el-radio>
              <el-radio label="zhumadian">驻马店市</el-radio>
              <el-radio label="jiyuan">济源市</el-radio>
              <el-radio label="development">省直管县行政区划</el-radio>
            </el-radio-group>
          </el-form-item>

          <el-form-item label="公告类型">
            <el-radio-group v-model="searchForm.type">
              <el-radio label="all">不限</el-radio>
              <el-radio label="procurement">采购公告</el-radio>
              <el-radio label="change">变更公告</el-radio>
              <el-radio label="result">结果公告</el-radio>
              <el-radio label="correction">更正公告</el-radio>
              <el-radio label="combined">合同公告</el-radio>
              <el-radio label="qualification">资格预审公告</el-radio>
              <el-radio label="onepackage">一事一议公告</el-radio>
              <el-radio label="evaluation">评审结果类</el-radio>
              <el-radio label="other">其他</el-radio>
            </el-radio-group>
          </el-form-item>

          <el-form-item label="采购方式">
            <el-radio-group v-model="searchForm.procurementMethod">
              <el-radio label="all">不限</el-radio>
              <el-radio label="public">公开招标</el-radio>
              <el-radio label="invitation">邀请招标</el-radio>
              <el-radio label="competitive">竞争性磋商</el-radio>
              <el-radio label="negotiation">谈判</el-radio>
              <el-radio label="singlesource">单一来源</el-radio>
              <el-radio label="enquiry">网上询价采购</el-radio>
              <el-radio label="reverse">网上反向竞价</el-radio>
              <el-radio label="agreement">协议供应/定点服务</el-radio>
              <el-radio label="government">竞争性磋商</el-radio>
              <el-radio label="other">其他</el-radio>
            </el-radio-group>
          </el-form-item>

          <div class="button-group">
            <el-button type="primary" @click="handleSearch">检索</el-button>
            <el-button @click="handleReset">重置</el-button>
          </div>
        </el-form>
      </div>
    </div>

    <!-- 检索结果列表 -->
    <div class="result-section">
      <div class="container result-container">
        <div class="result-header">
          <div class="result-title">检索结果</div>
          <div class="result-sort">
            <el-dropdown>
              <span class="el-dropdown-link">
                按时间排序 <i class="el-icon-arrow-down"></i>
              </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item>按时间排序</el-dropdown-item>
                  <el-dropdown-item>按相关度排序</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </div>
        </div>

        <div class="result-list">
          <div v-for="(item, index) in resultList" :key="index" class="result-item">
            <div class="result-item-title">
              <router-link :to="'/detail/' + item.id">{{ item.title }}</router-link>
            </div>
            <div class="result-item-info">
              <span class="procurement-type">{{ item.purchaser }}</span>
              <span class="region-info">{{ item.region }}</span>
              <span class="budget">{{ item.type }}</span>
              <!-- <span class="view-count">{{ item.viewCount }}人查看</span> -->
              <!-- <span v-if="item.status" class="status">{{ item.type }}</span> -->
            </div>
            <div class="result-item-date">发布时间：{{ item.publishTime }}</div>
          </div>
        </div>

        <!-- 分页 -->
        <div class="pagination">
          <el-pagination
            layout="total, prev, pager, next, jumper, sizes"
            :total="totalItems"
            :page-size="pageSize"
            :current-page="currentPage"
            :page-sizes="[10, 20, 50, 100]"
            @current-change="handlePageChange"
            @size-change="handleSizeChange"
          ></el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
  import { ref, reactive, onMounted } from 'vue';
  import { bidList } from '@/api/bid';

  // 当前激活的标签页
  const activeTab = ref('announcement');

  // 搜索表单数据
  const searchForm = reactive({
    title: '',
    purchaser: '',
    projectNumber: '',
    publishOrgin: '',
    timeRange: '',
    customDateRange: [],
    region: '',
    type: '',
    procurementMethod: ''
  });

  // 分页相关
  const currentPage = ref(1);
  const pageSize = ref(10);
  const totalItems = ref(271);

  // 模拟结果列表数据
  const resultList = ref([
    {
      id: 1,
      title: '新乡航空运输学院合宿舍区食育及卫生体育局2024年体育设施购置项目一标段（三次）公开招标公告',
      procurementType: '河南省-体育局-体育类',
      region: '新乡市',
      budget: '7700.00万元',
      viewCount: '29',
      publishDate: '2024-12-15'
    },
    {
      id: 2,
      title: '长葛市教育体育局2025年1月政府采购公告',
      procurementType: '河南省-体育局-体育类',
      region: '许昌市',
      budget: '907万元',
      publishDate: '2024-12-15'
    },
    {
      id: 3,
      title: '平顶山市体育运动学校办公设备及室内运动器械重庆工程竞争性磋商公告',
      procurementType: '河南省-平顶山市-体育类',
      region: '平顶山市',
      budget: '15.2976万元',
      viewCount: '29',
      publishDate: '2024-12-14'
    },
    {
      id: 4,
      title: '杞县大同实验中学器材装备采购及设备采购项目（二次）二标段公告',
      procurementType: '河南省-开封市-体育',
      region: '开封市',
      budget: '19万元人民币',
      viewCount: '17',
      publishDate: '2024-12-14'
    },
    {
      id: 5,
      title: '洛阳市龙津区教育体育局企业三云智慧课堂采购项目-竞争性磋商公告',
      procurementType: '河南省-洛阳市-体育类',
      region: '洛阳市',
      budget: '277万元',
      viewCount: '27',
      publishDate: '2024-12-13'
    },
    {
      id: 6,
      title: '濮阳市文化广电旅游局常规市级文体教育训练项目竞争性磋商公告',
      procurementType: '河南省-濮阳市-体育局',
      region: '濮阳市',
      budget: '150万元',
      viewCount: '27',
      publishDate: '2024-12-13'
    },
    {
      id: 7,
      title: '濮阳市文化广电体育局游泳馆游泳类文体教育训练项目-竞争性磋商公告',
      procurementType: '河南省-濮阳市-体育局',
      region: '濮阳市',
      budget: '150万元',
      viewCount: '17',
      status: '询标中',
      publishDate: '2024-12-12'
    },
    {
      id: 8,
      title: '宜阳县教育体育局宜阳县禽蛋镇门沟小学附属幼儿园装修作业及附属工程-竞争性磋商公告',
      procurementType: '河南省-洛阳市-宜阳县',
      region: '洛阳市',
      budget: '63.3087万元',
      viewCount: '37',
      publishDate: '2024-12-12'
    },
    {
      id: 9,
      title: 'YZCG-T2024030鹿邑市教育体育局学前教育电子设备工程项目',
      procurementType: '河南省-体育局-周口市',
      region: '周口市',
      budget: '48.397万元',
      viewCount: '37',
      status: '询标中',
      publishDate: '2024-12-12'
    },
    {
      id: 10,
      title: '长垣市康乐街道子高中心幼儿园体育设备项目-中标公告',
      procurementType: '河南省-新乡市-长垣市',
      region: '新乡市',
      budget: '',
      viewCount: '29',
      publishDate: '2024-12-12'
    }
  ]);

  // 搜索方法
  const handleSearch = () => {
    console.log('搜索表单数据:', searchForm);
    // 标题关键字搜索
    let search = {
      title: searchForm.title ? `*${searchForm.title}*` : searchForm.title,
      purchaser: searchForm.purchaser ? `*${searchForm.purchaser}*` : searchForm.purchaser,
      region: searchForm.region ? `*${searchForm.region}*` : searchForm.region,
      publishOrgin: searchForm.publishOrgin? `*${searchForm.publishOrgin}*` : searchForm.publishOrgin,
    };

    bidList({ pageNo: 1, pageSize: 10, ...search }).then(res => {
      resultList.value = res.records;
    }).catch(err => {
      console.log(err)
      EleMessage.error(e.message);
    })
    currentPage.value = 1;
  };

  // 重置搜索表单
  const handleReset = () => {
    Object.keys(searchForm).forEach(key => {
      if (typeof searchForm[key] === 'string') {
        searchForm[key] = '';
      } else if (Array.isArray(searchForm[key])) {
        searchForm[key] = [];
      }
    });
    searchForm.timeRange = '';
    searchForm.region = '';
    searchForm.type = '';
    searchForm.procurementMethod = '';
  };

  // 页码变化处理
  const handlePageChange = (val) => {
    currentPage.value = val;
    // 这里可以调用API获取对应页的数据
  };

  // 每页条数变化处理
  const handleSizeChange = (val) => {
    pageSize.value = val;
    currentPage.value = 1;
    // 这里可以调用API获取对应条数的数据
  };

  // 初始化时获取数据
  onMounted(() => {
    handleSearch();
  });
</script>
<style scoped>
.procurement-platform {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-color: #f0f2f5;
}

.container {
  width: 1200px;
  margin: 0 auto;
}

/* 头部样式 */
.header {
  background-color: #3a4151;
  color: white;
  padding: 10px 0;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo-container {
  display: flex;
  align-items: center;
}

.logo {
  width: 40px;
  height: 40px;
  margin-right: 10px;
  border-radius: 50%;
  background-color: white;
}

.logo-text {
  font-size: 18px;
  font-weight: bold;
}

.nav-menu {
  display: flex;
  gap: 20px;
}

.nav-item {
  color: white;
  text-decoration: none;
  padding: 5px 10px;
}

.nav-item.active {
  border-bottom: 2px solid white;
  font-weight: bold;
}

.user-actions {
  display: flex;
  align-items: center;
}

/* 搜索区域样式 */
.search-section {
  background-color: white;
  padding: 20px 0;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.search-container {
  padding: 20px;
  border-radius: 4px;
}

.button-group {
  display: flex;
  justify-content: center;
  margin-top: 20px;
  gap: 20px;
}

/* 结果列表样式 */
.result-section {
  flex: 1;
  padding: 20px 0;
}

.result-container {
  background-color: white;
  padding: 20px;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 15px;
  border-bottom: 1px solid #eee;
  margin-bottom: 15px;
}

.result-title {
  font-size: 18px;
  font-weight: bold;
}

.result-item {
  padding: 15px 0;
  border-bottom: 1px solid #eee;
}

.result-item-title {
  font-size: 16px;
  margin-bottom: 10px;
}

.result-item-title a {
  color: #1890ff;
  text-decoration: none;
}

.result-item-info {
  font-size: 14px;
  color: #666;
  margin-bottom: 8px;
}

.result-item-info span {
  margin-right: 15px;
}

.status {
  color: #1890ff;
}

.result-item-date {
  font-size: 14px;
  color: #999;
}

.pagination {
  margin-top: 20px;
  display: flex;
  justify-content: center;
}

/* 页脚样式 */
.footer {
  background-color: #3a4151;
  color: white;
  padding: 30px 0;
  margin-top: 20px;
}

.footer-content {
  display: flex;
  flex-direction: column;
}

.footer-top {
  display: flex;
  justify-content: space-between;
  padding-bottom: 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.footer-logo {
  display: flex;
  align-items: center;
}

.footer-logo-img {
  width: 40px;
  height: 40px;
  margin-right: 10px;
  border-radius: 50%;
  background-color: white;
}

.footer-contact {
  max-width: 300px;
}

.footer-contact h3, .quick-nav h3 {
  margin-bottom: 10px;
  font-size: 16px;
}

.footer-contact p {
  margin: 5px 0;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.8);
}

.footer-qrcode {
  display: flex;
  gap: 20px;
}

.qrcode-item {
  text-align: center;
}

.qrcode-item img {
  width: 100px;
  height: 100px;
  background-color: white;
  margin-bottom: 5px;
}

.qrcode-item p {
  font-size: 14px;
}

.footer-bottom {
  padding-top: 20px;
  text-align: center;
}

.quick-nav {
  margin-bottom: 15px;
}

.quick-nav a {
  color: white;
  text-decoration: none;
  margin: 0 10px;
}

.footer-links {
  margin-bottom: 10px;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.8);
}

.footer-links a {
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
}

.copyright {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.6);
}

/* 响应式调整 */
@media (max-width: 1200px) {
  .container {
    width: 95%;
  }
}

@media (max-width: 768px) {
  .footer-top {
    flex-direction: column;
    gap: 20px;
  }

  .search-container .el-form-item {
    margin-bottom: 10px;
  }

  .nav-menu {
    display: none;
  }
}
</style>
